It's easy to think of a command as a built-in function within CMD.EXE
and a utility as an external application that you run. However, the
command line presents a third alternative, one that you might not have
ever considered. The RunDLL32.EXE
file is a utility that you can't run directly. Instead, you feed it a
DLL that contains one or more externally accessible functions and add
any arguments that the function requires as part of your input. For
example, let's say you want to add a beep to your batch file. You can
use the MessageBeep() function found in the User32.DLL file by adding this command to a batch file or script.
RunDLL32 User32.DLL,MessageBeep
Notice that you type the utility name, RunDLL32, followed by the name of the DLL, User32.DLL, and the name of the function, MessageBeep(). Note that the capitalization of the function you call is important; MessageBeep isn't the same as messagebeep.
You
have many resources for learning how to use this particular command
line feature. The best place to begin learning is the registry. Simply
open the RegEdit utility and search for RunDLL32 entries by selecting
the Edit Find command and typing RunDLL32 in the Find What field. Figure 1 shows a typical entry. In this case, the example shows how to install a new screen saver using the RunDLL32 utility (a handy thing to know since there isn't any way to do it from the user interface).
Notice that, in this case, you pass the name of the screen saver file to the function. Replace any variable entries, %1
in this case, with the actual filename you want to use when working at
the command line. You'll find a wealth of RunDLL32 tips online,
including suggested commands. Make sure you always understand what a
command will do and verify its functionality before you actually use
it. Some wannabe comedians use their Web sites to get you to do odd and
dangerous things to your computer. One of the better Web sites to try
is Using Rundll at http://www.ericphelps.com/batch/rundll/.
The
registry might not contain a solution for every need. You can look at
the DLLs directly using an application such as Depends (Dependency
Walker). You can't use the Dependency Walker at the Server Core
console, but you can use it at a client machine. This particular
utility is used so often by developers that it has its own Web site at
http://www.dependencywalker.com/ with appropriate download links for
various platforms. Figure 2
shows a typical view of a DLL opened in the Depends utility. Most of
the information displayed in this figure has nothing to do with the
command line and you can ignore it. However, the second window on the
right side of the display shows the list of functions in the DLL.
Of
course, Depends won't tell you what task the function performs or how
to use it. To an extent, you're left on your own as far as usage
details and you'll definitely want to spend time online looking for
suggestions. However, you can get complete details on the function when
working with any Microsoft DLL on the MSDN Library Web site at http://msdn.microsoft.com/library/.
Simply type the function name in the Search For field and click Search.
Other vendors usually provide similar documentation that you can use to
learn more about the functions on their Web sites within DLLs.
Server
Core (and most newer versions of Windows) places significant security
restrictions on users. Consequently, some RunDLL32 solutions that
worked in the past might not work today. Always test a RunDLL32
solution using the same privileges as the anticipated user, rather than
your own privileges, which are likely more inclusive. |